<?php

ob_start();
/**
 * OrangeHRM is a comprehensive Human Resource Management (HRM) System that captures
 * all the essential functionalities required for any enterprise.
 * Copyright (C) 2006 OrangeHRM Inc., http://www.orangehrm.com
 *
 * OrangeHRM is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * OrangeHRM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA
 *
 */

define('ROOT_PATH', dirname(__FILE__));
$_SESSION['path']=ROOT_PATH;
require_once ROOT_PATH . '/lib/common/CommonFunctions.php';
require_once ROOT_PATH . '/lib/models/eimadmin/EmployStat.php';

require_once ROOT_PATH . '/lib/common/Language.php';
$lan = new Language();
//require_once ROOT_PATH . '/language/default/lang_default_full.php';
//require_once ROOT_PATH . '/lib/common/xajax/xajax.inc.php';
//require_once ROOT_PATH . '/lib/common/xajax/xajaxElementFiller.php';
require_once($lan->getLangPath("full.php"));

session_start();

// To test a different style, can use http://host/orangehrm/login.php?styleSheet=abc
$styleSheet = CommonFunctions::getTheme();
$_SESSION['styleSheet'] = $styleSheet;

$wpath = explode('/login.php', $_SERVER['REQUEST_URI']);
$_SESSION['WPATH']= $wpath[0];

require_once ROOT_PATH . '/lib/models/eimadmin/Login.php';
require_once ROOT_PATH . '/lib/common/authorize.php';

/* LDAP Module */

$ldapFile = ROOT_PATH . "/plugins/ldap/LdapLogin.php";
$_SESSION['ldap'] = "enabled";
$_SESSION['ldapStatus'] = "enabled";
// echo "login check";
if (file_exists($ldapFile)) {
	require_once ROOT_PATH . '/plugins/PlugInFactoryException.php';
	require_once ROOT_PATH . '/plugins/PlugInFactory.php';
	$_SESSION['ldap'] = "enabled";
	require_once $ldapFile;
	$ldap = PlugInFactory::factory("LDAP");
	
	if($ldap->checkAuthorizeLoginUser("Admin") && $ldap->checkAuthorizeModule("Admin")){
		$ldapStatus = $ldap->retrieveLdapStatus();
		$_SESSION['ldapStatus'] = $ldapStatus;
	}else{
		throw new PlugInFactoryException(PlugInFactoryException::PLUGIN_INSTALL_ERROR);
	}
}

/* LDAP Module */

/* Print Benefits Module */

$benefitsFile = ROOT_PATH . "/plugins/printBenefits/pdfHspSummary.php";
$_SESSION['printBenefits'] = "disabled";

if (file_exists($benefitsFile)) {
	$_SESSION['printBenefits'] = "enabled";
}

/* Print Benefits Module */

if ((isset($_POST['actionID'])) && $_POST['actionID'] == 'chkAuthentication') {

	$login = new Login();
	$rset=$login->filterUser(trim($_POST['txtUserName']));
	//error_log(md5(""),3,"C:/logtest.log");
	if ($_SESSION['ldapStatus'] == "enabled") {
			$ldapAuth = $ldap->ldapAuth($rset[0][0], $_POST['txtPassword']);
			if ($ldapAuth) { // stuff in normal login process
				$_SESSION['ladpUser'] = true;

				if ($rset[0][5]=='Enabled') {
					if (($rset[0][7] == "Yes") || (($rset[0][7] == "No") && !empty($rset[0][6]))) {
						$_SESSION['user']=$rset[0][3];
						$_SESSION['userGroup']=$rset[0][4];
						$_SESSION['isAdmin']=$rset[0][7];
						$_SESSION['empID']=$rset[0][6];
						$_SESSION['userName']=$_POST['txtUserName'];
						$_SESSION['fname']=$rset[0][2];

						/* If not an admin user, check if a supervisor and/or project admin */
						$isSupervisor = false;
						$isProjectAdmin = false;
                		$isManager = false;
                		$isDirector = false;
                		$isAcceptor = false;
                		$isOfferer = false;
						if ($_SESSION['isAdmin'] == 'No') {

						$authorizeObj = new authorize($_SESSION['empID'], $_SESSION['isAdmin']);
						$isSupervisor = $authorizeObj->isSupervisor();
						$isProjectAdmin = $authorizeObj->isProjectAdmin();
                    	$isManager = $authorizeObj->isManager();
                    	$isDirector = $authorizeObj->isDirector();
                    	$isAcceptor = $authorizeObj->isAcceptor();
                    	$isOfferer = $authorizeObj->isOfferer();
					}
					$_SESSION['isSupervisor'] = $isSupervisor;
					$_SESSION['isProjectAdmin'] = $isProjectAdmin;
                	$_SESSION['isManager'] = $isManager;
					$_SESSION['isDirector'] = $isDirector;
					$_SESSION['isAcceptor'] = $isAcceptor;
					$_SESSION['isOfferer'] = $isOfferer;

					$wpath = explode('/login.php', $_SERVER['REQUEST_URI']);
					$_SESSION['WPATH']= $wpath[0];

					// TODO: Can set user specific stylesheet here.
					$_SESSION['styleSheet'] = $styleSheet;

					setcookie('Loggedin', 'True', 0, '/');

					header("Location: ./index.php");
					} else {
						$InvalidLogin=3;
					}
				} else {
					$InvalidLogin=2;
				}
			} else {
				$InvalidLogin = 1;
			}

	}else if (md5($_POST['txtPassword']) == $rset[0][1]) {
		if ($rset[0][8] == EmploymentStatus::EMPLOYMENT_STATUS_ID_TERMINATED) {
			$InvalidLogin=5;
		} else if ($rset[0][5]=='Enabled') {
			if (($rset[0][7] == "Yes") || (($rset[0][7] == "No") && !empty($rset[0][6]))) {
				$_SESSION['user']=$rset[0][3];
				$_SESSION['userGroup']=$rset[0][4];
				$_SESSION['isAdmin']=$rset[0][7];
				$_SESSION['empID']=$rset[0][6];
				$_SESSION['userName']=$_POST['txtUserName'];
				$_SESSION['fname']=$rset[0][2];

				/* If not an admin user, check if a supervisor and/or project admin */
				$isSupervisor = false;
				$isProjectAdmin = false;
           		$isManager = false;
                $isDirector = false;
                $isAcceptor = false;
                $isOfferer = false;

				if ($_SESSION['isAdmin'] == 'No') {

					$authorizeObj = new authorize($_SESSION['empID'], $_SESSION['isAdmin']);
					$isSupervisor = $authorizeObj->isSupervisor();
					$isProjectAdmin = $authorizeObj->isProjectAdmin();
                   	$isManager = $authorizeObj->isManager();
                    $isDirector = $authorizeObj->isDirector();
                    $isAcceptor = $authorizeObj->isAcceptor();
                    $isOfferer = $authorizeObj->isOfferer();

				}
				$_SESSION['isSupervisor'] = $isSupervisor;
				$_SESSION['isProjectAdmin'] = $isProjectAdmin;
                $_SESSION['isManager'] = $isManager;
				$_SESSION['isDirector'] = $isDirector;
				$_SESSION['isAcceptor'] = $isAcceptor;
				$_SESSION['isOfferer'] = $isOfferer;

				$wpath = explode('/login.php', $_SERVER['REQUEST_URI']);
				$_SESSION['WPATH']= $wpath[0];

				// TODO: Can set user specific stylesheet here.
				$_SESSION['styleSheet'] = $styleSheet;

				setcookie('Loggedin', 'True', 0, '/');

				header("Location: ./index.php");
			} else {
				$InvalidLogin=3;
			}
		} else $InvalidLogin=2;
	} else {
		$InvalidLogin=1;
	}
}
require_once ROOT_PATH . '/lib/extractor/news/EXTRACTOR_newslist.php';
require_once ROOT_PATH . '/lib/extractor/news/EXTRACTOR_news.php';
require_once ROOT_PATH . '/lib/controllers/NewsController.php';

$viewListExtractor = new EXTRACTOR_newsList();	
$newsObj = new NewsController();
$searchObject = $viewListExtractor->parseSearchData($_POST, $_GET);
$objResult= $newsObj->_viewListNewsPublic($searchObject);	

$listNews = $objResult[0];
$listEvent = $objResult[1];
$listAnnounce = $objResult[2];
$baseURL = './lib/controllers/CentralController.php?newscode=Vacancy';

?>


<html>
<head>

<title><?php echo $lang_login_title; ?></title>
<link href="favicon.ico" rel="icon" type="image/gif"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="../../scripts/archive.js"></script>
<script type="text/javascript" src="../../scripts/octopus.js"></script>
<style type="text/css">@import url("themes/<?php echo $styleSheet;?>/css/menu.css"); </style>
<style type="text/css">@import url("themes/<?php echo $styleSheet;?>/css/style.css"); </style>
<style type="text/css">@import url("themes/<?php echo $styleSheet;?>/css/login.css"); </style>



<link href="themes/<?php echo $styleSheet; ?>/css/style.css" rel="stylesheet" type="text/css">
<style type="text/css">
@import url("../../themes/beyondT/css/octopus.css");
.roundbox {
        margin-top: 10px;
        margin-left: 0px;
        width: 98%;
        //  border: 2px solid #000000;
    }

    .roundbox_content {
        padding:15px;
    }
    
    #rightMenu {
	z-index: 0;
	
}
</style>


<script language=javascript src="scripts/ypSlideOutMenus.js"></script>
<script>

	function submitForm() {

		if(document.loginForm.txtUserName.value == "") {
				alert(' <?php echo $lang_login_UserNameNotGiven; ?>');
				return false;
		   }

		if(document.loginForm.txtPassword.value == "") {
				alert("<?php echo $lang_login_PasswordNotGiven; ?>");
				return false;
		   }

		document.loginForm.actionID.value = "chkAuthentication";
		document.loginForm.submit();
	}

	if (window.parent != window) {
		window.parent.location.reload();
	}
</script>


<script language="JavaScript">
//window.onresize = setSize();

		//var yPosition = 108;
		var yPosition = 150;

		var agt=navigator.userAgent.toLowerCase();

		var xPosition = 172;

		if (agt.indexOf("konqueror") != -1) var xPosition = 172;

		if (agt.indexOf("windows") != -1) var xPosition = 172;

		if (agt.indexOf("msie") != -1) var xPosition = 172;


		new ypSlideOutMenu("menu1", "right", xPosition, yPosition, 172, 230)
		new ypSlideOutMenu("menu2", "right", xPosition, yPosition + 25, 172, 360)
		new ypSlideOutMenu("menu3", "right", xPosition, yPosition + 50, 172, 220)
		new ypSlideOutMenu("menu4", "right", xPosition, yPosition + 75, 172, 80)
		new ypSlideOutMenu("menu5", "right", xPosition, yPosition + 100, 172, 130)
		new ypSlideOutMenu("menu9", "right", xPosition, yPosition + 125, 172, 80)		
		 new ypSlideOutMenu("menu12", "right", xPosition, yPosition + 150, 172, 120)
		new ypSlideOutMenu("menu15", "right", xPosition, yPosition + 175, 172, 120)
		new ypSlideOutMenu("menu17", "right", xPosition, yPosition + 200, 172, 120)
		
		/*
		new ypSlideOutMenu("menu12", "right", xPosition, yPosition + 44, 146, 120)
		new ypSlideOutMenu("menu15", "right", xPosition, yPosition + 66, 146, 120)
		new ypSlideOutMenu("menu17", "right", xPosition, yPosition + 88, 146, 120)
		*/
		new ypSlideOutMenu("menu18", "right", xPosition, yPosition + 198, 172, 120)//CVS
		new ypSlideOutMenu("menu13", "right", xPosition, yPosition, 172, 172)
		new ypSlideOutMenu("menu14", "right", xPosition, yPosition + 22, 172, 120)
		new ypSlideOutMenu("menu16", "right", xPosition, yPosition, 146, 172)
		new ypSlideOutMenu("menu19", "right", xPosition, yPosition, 146, 172)//HSP
		new ypSlideOutMenu("menu20", "right", xPosition, yPosition + 16, 172, 120)

function swapImgRestore() {
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function preloadImages() {
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}
function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function swapImage() {
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function showHideLayers() {
  var i,p,v,obj,args=showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style	; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function setSize() {
	var iframeElement = document.getElementById('rightMenu');
	iframeElement.style.height = (window.innerHeight - 20) + 'px'; //100px or 100%
	iframeElement.style.width = '100%'; //100px or 100%
}
function preloadAllImages() {
	var base = 'themes/<?php echo $styleSheet; ?>/pictures';
	preloadImages(base + '/buttonplain.gif', base + '/buttonplain_o.gif');
}
</SCRIPT>


</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" >
<noscript>
	<strong><font color='Red' style="padding-left:15px; text-decoration:blink;">
		<?php echo $lang_login_NeedJavascript;?>
		<a href="http://www.mozilla.com/firefox/" target="_blank"
			style="text-decoration:none;"><?php echo $lang_login_MozillaFirefox;?></a>
		</font>
	</strong>
</noscript>
<?php  if (isset($_COOKIE['Loggedin']) && isset($_SERVER['HTTP_REFERER'])) { ?>
	<strong><font color='Red' style="padding-left:15px;"><?php echo $lang_login_YourSessionExpired;?></font>
	</strong>
<?php } ?>

<center>

<table width="1000" height="835"  style="border-left: 1px solid #DADADA;border-right: 1px solid #DADADA;border-bottom: 1px solid #DADADA" cellspacing="0" cellpadding="0" align="center">
<!-- Header -->
<tr height="50">
	<td>
		<table border="0" cellspacing="0" cellpadding="0">
			<tr height="50">		
				<td title="Company Logo" class="companyLogoHeader" /></td>
      	     </tr>	
		</table>
	</td>
</tr>

<!-- Welcome -->

<tr height="20">
	<td>
		<table border="0" cellspacing="0" cellpadding="0">
			<tr height="20">
			    <td class="subTabBar" align="center" valign="top">
				    <table border="0" align="center" cellpadding="0" cellspacing="0" width="1000">
				        <tr>
				            <td class="welcome" width="100%"> Welcome to S3HRM Intranet System</td>
				            <td class="welcome" align="right" nowrap="nowrap"></td>            
							<td  class="welcome"></td>
							<td height="22" nowrap="nowrap"></td>				
				            <td class="welcome" align="right" nowrap="nowrap"></td>				              
							<td class="welcome" align="right" nowrap="nowrap"></td>							
							<td class="welcome" align="right" nowrap="nowrap"> </td>							     
				          </tr>
				      </table>
			    </td>
		     </tr>
		</table>
	</td>
</tr>

<!-- Body -->
<tr>
	<td valign="top">
		<table border="0" cellspacing="0" cellpadding="0">
			<tr>
				<!-- Right Menu -->		
				<td valign="top">
					<table border="0" cellspacing="0" cellpadding="0">
						<tr>
		      				<td width="200" valign="top" >
					         	<TABLE cellSpacing=0 cellPadding=0 border="0" >
					             <TBODY>
					               <TR vAlign=top>
									  <TD valign="top" width=158>
						                 <ul id="menu">
						                 		 <?php $host = $_SERVER['HTTP_HOST']; ?>
						                 		 <li ><a href="http://<?php echo $host; ?>/wiki/" target="_new">S3 Wiki </a></li>
						                 		<li ><a href="https://<?php echo $host; ?>/bugzilla/" target="_new">Bugzilla </a></li>            	 
						  						<li><a href="http://<?php echo $host; ?>/mrbs/" target="_new">Booking room </a></li>	
						  						<li ><a href="http://<?php echo $host; ?>/support/" target="_new">Support system </a></li>
						  						
												 <li ><a href="http://<?php echo $host; ?>:3000/" target="_new">Collaboration Tool </a></li>

						  						<!--<li ><a href="http://<?php echo $host; ?>/AUP/index.html" target="_new">Agile Unified Process  </a></li> -->
                                                                                                <li ><a href="https://changepassword.s3corp.com.vn" target="_new">Change Password </a></li>
						  				  </ul>
						  				</td>
					                </TR>
					              </TBODY>
					           </TABLE>
					      </td>
					    </tr>			
					</table>
				</td>
				<!--login form  -->
				<td>
					<table border="0" cellspacing="0" cellpadding="0"  >
								<tr>	
			    					<td width="500" height="300" valign="middle" align="center">    				 
							    		<div id="login_container" >			   
								    		
								    			<form name="loginForm" method="post" action="./login.php" onSubmit="submitForm(); return false;">
													<input type="hidden" name="actionID"></input>	
								      			<div class="login_box" >	
								      								
								        								          			
											        <?php if(isset($_POST['txtUserName'])) {?>
									              		<p class="pad"><input type ="textbox" name="txtUserName" styleClass="input" value="<?php echo $_POST['txtUserName']?>"></p>
														<?php		} else { ?>
									              		 <p class="pad"><input type ="textbox" name="txtUserName" styleClass="input" value=""/></p>
														<?php		} ?>
								         
							          				<p class="pad"><input name="txtPassword" type="password" styleClass="input" value=""/></p>					          
								          			<p class="pad"><input type="Submit" name="Submit" value="<?php echo $lang_login_Login; ?>" class="button" > </p>
								          			
							      				</div>
							      				</form>	
							      				<?php if(isset($InvalidLogin)) {?>
									            	<?php
													if(isset($InvalidLogin)) {
													   switch ($InvalidLogin) {							
													   		case 1 : 	$InvalidLoginMes = $lang_login_InvalidLogin;
													   					break;
													   		case 2 : 	$InvalidLoginMes = $lang_login_UserDisabled;
													   					break;
													   		case 3 : 	$InvalidLoginMes = $lang_login_NoEmployeeAssigned;
													   					break;
													   		case 4 : 	$InvalidLoginMes = $lang_login_temporarily_unavailable;
													   					break;
													   		case 5 :    $InvalidLoginMes = $lang_login_EmployeeTerminated;
													   					break;							
												  	 }
													} else {
											      	 $InvalidLoginMes = "&nbsp;";
													}
									
													$longMessage = "";
									
													if (strlen($InvalidLoginMes) > 14){
														$longMessage = $InvalidLoginMes;
														$InvalidLoginMes = "<a title='{$longMessage}' >".substr($InvalidLoginMes, 0, 11)."...</a>";
													}
													?>
													 <p><strong ><font color='Red'><?php echo $InvalidLoginMes; ?></font></strong></p>
								        			<?php } ?>      
								   		 	
								   		</div>
								   	
									</td>
			    				</tr>						
					</table>
				</td>
      	     </tr>	
		</table>
	</td>
</tr>
<!-- Footer -->
<tr>
	<td >
		<table border="0" cellspacing="0" cellpadding="0" width="100%" >
			<tr>
				<?php $curYear = date('Y'); ?>
				<td align="center" height="30" valign="middle"  style="border-top: 1px solid #DADADA;" width="100%">All rights reserved by <a href="http://s3corp.com.vn" target="_blank">Sunrise Software Solutions Corporation </a> - Copyright 2008 - <?php echo $curYear; ?> </td>
			</tr>
		</table>
	</td>
</tr>

</table>

</center>
<script language="javascript">
function windowDimensions() {
	if (document.compatMode && document.compatMode != "BackCompat") {
   		x = document.documentElement.clientWidth;
	} else {
   		x = document.body.clientWidth;
   	}
   	y = document.body.clientHeight;

   	return [x,y];
}
function exploitSpace() {
	dimensions = windowDimensions();

	if (document.getElementById("rightMenu")) {
		document.getElementById("rightMenu").height = dimensions[1]-130;
	}

	if (document.getElementById("rightMenuHolder")) {
		document.getElementById("rightMenuHolder").width = dimensions[0]-200;
	}
}

exploitSpace();
window.onresize = exploitSpace;
</script>
<script type="text/javascript">
<!--
   	if (document.getElementById && document.createElement) {
		initOctopus();
	}
-->

</script>


</body>
</html>
